package net.brucecooper.mindmap.client;

import java.util.ArrayList;
import java.util.List;


public class NodeSelectionManager {

    private int selected = -1;
    private List<NodeSelectionListener> listeners = new ArrayList<NodeSelectionListener>();
    
    public void select(int newSelection) {

    	if (newSelection != selected) {
	        this.selected = newSelection;
	        // TODO this could fire off events unnecessarily.  Be careful of new NodeWidgets with the same selection as the old ones.
	        for (NodeSelectionListener l: listeners) {
	            l.nodeSelectionChanged();
	        }
    	}
    }
    
    
    public int getSelected() {
        return selected;
    }
    
    public void addSelectionListener(NodeSelectionListener listener) {
        listeners.add(listener);
    }
}
